<?php
if( !defined( 'VARIABLE' ) ): define( 'VARIABLE', 1 );
if( !defined( 'FILE_ROOT' ) ) include_once( '../../_prerun' );

/**
 * Table VARIABLE
 */
final class Variable
	{
	///////////////////////////////////////////////////////
	protected static $collection = null;
	///////////////////////////////////////////////////////
	protected static $instance = null;

	///////////////////////////////////////////////////////
	protected function __construct()
		{
		include_once APP_ROOT . 'preferences/users_vars.class.php5';
		$vars = new Users_vars( '_VARIABLES_' );
		self::$collection = array();
		$collection = $vars->getElementsByParams();
		foreach( $collection as $index => $values )
			{
			self::$collection[ $values[ 'f_php_code' ] ] = $values;
			}
		}

	///////////////////////////////////////////////////////
	public static function buildInstance()
		{
		if( isset( self::$instance ) ) return;
		self::$instance = new Variable();
		}

	///////////////////////////////////////////////////////
	public static function exist( $name )
		{
		Variable::buildInstance();
		return( isset( Variable::$collection[ $name ] ) );
		}

	///////////////////////////////////////////////////////
	public static function get( $name )
		{
		Variable::buildInstance();
		if( isset( Variable::$collection[ $name ] ) )
			{
			if( Variable::$collection[ $name ][ 'f_type' ] == 'html' )
				return Variable::$collection[ $name ][ 'f_value' ];
			else
			if( Variable::$collection[ $name ][ 'f_type' ] == 'input' )
				return strip_tags( Variable::$collection[ $name ][ 'f_value' ] );
			else
			if( Variable::$collection[ $name ][ 'f_type' ] == 'file' )
				return Variable::$collection[ $name ][ 'f_filename' ];
			else
			if( Variable::$collection[ $name ][ 'f_type' ] == 'image' )
				return Variable::$collection[ $name ][ 'f_filename' ];
			}
		else
			return null;
		}

	///////////////////////////////////////////////////////
	public static function getFilename( $name )
		{
		Variable::buildInstance();
		if( isset( Variable::$collection[ $name ] ) )
			{
			if( isset( Variable::$collection[ $name ][ 'f_filename' ] ) )
				return Variable::$collection[ $name ][ 'f_filename' ];
			else
				return '';
			}
		else
			return null;
		}

	///////////////////////////////////////////////////////
	public static function getValue( $name )
		{
		Variable::buildInstance();
		if( isset( Variable::$collection[ $name ] ) )
			{
			return Variable::$collection[ $name ][ 'f_value' ];
			}
		else
			return null;
		}

	///////////////////////////////////////////////////////
	public static function getTitle( $name )
		{
		Variable::buildInstance();
		if( isset( Variable::$collection[ $name ] ) )
			{
			return Variable::$collection[ $name ][ 'f_title' ];
			}
		else
			return null;
		}

	///////////////////////////////////////////////////////
	public static function getCollection()
		{
		Variable::buildInstance();
		return self::$collection;
		}
	}

endif;
?>